package main

import "fmt"

func main(){
	// duplex channel
	ch1:=make(chan string,5)
	array:=[5]string{"Python","Java","C","Go","TypeScript"}
	for i:=0;i<5;i++{
		ch1<-array[i]
	}
	// closed channel can be read but cannot be written
	close(ch1)
	for i:=0;i<5;i++{
		msg,ok := <-ch1
		if(ok){
			fmt.Println(msg)
		}
	}
	// unidirectional channel
	type Receiver <-chan int
	type Sender chan<- int
	var ch2 = make(chan int,0)
	var sender Sender = ch2
	var receiver Receiver = ch2
	var num int
	go func(){
		num = <-receiver
	}()
	sender<-666
	fmt.Println(num)
	// iterate a channel
	ch3:=make(chan int,10)
	go send(5,ch3)
	for i := range ch3{
		fmt.Println(i)
	}
}

func send(n int,ch chan int){
	for i:=0;i<n;i++{
		ch <- i
	}
	close(ch)
}
